﻿#region Includes
using System;
#endregion

namespace GingerGL.Graphics
{
    //------------------------------------------------------------//
    /// <summary>
    /// Standard Viewport Class
    /// </summary>
    public class Viewport
    {
        //--------------------------------------------------------//
        #region Properties
        /// <summary>
        /// Gets default viewport
        /// </summary>
        static public Viewport Default { get { return new Viewport(); } }
        /// <summary>
        /// Gets/Sets the aspect ratio (width/height ).
        /// </summary>
        public float AspectRatio { get; set; }
        /// <summary>
        /// Gets/Sets the field of view in degrees.
        /// </summary>
        public float FieldOfView { get; set; }
        /// <summary>
        /// Gets/Sets the distance from the camera to the viewports near
        /// plane. Anything on the cameras tRight of this plane is clipped.
        /// </summary>
        public float NearClipdistance { get; set; }
        /// <summary>
        /// Gets/Sets the distance from the camera to the viewports far
        /// plane. Anything on the opposite tRight of this plane from the camera
        /// is clipped.
        /// </summary>
        public float FarClipDistance { get; set; }
        #endregion
        //--------------------------------------------------------//
        #region Constructor
        /// <summary>
        /// Initializes a new instance of object
        /// </summary>
        public Viewport()
        {
            this.AspectRatio = 1f;
            this.FieldOfView = 45f;
            this.NearClipdistance = 0.1f;
            this.FarClipDistance = 5000f;
        }
        #endregion
        //--------------------------------------------------------//
        #region Methods
        /// <summary>
        /// Equals
        /// </summary>
        public override bool Equals(object obj)
        {
            if (obj is Viewport)
            {
                Viewport o = (Viewport)obj;
                return this.AspectRatio == o.AspectRatio
                    && this.FarClipDistance == o.FarClipDistance
                    && this.FieldOfView == o.FieldOfView
                    && this.NearClipdistance == o.NearClipdistance;
            }
            else return false;
        }
        /// <summary>
        /// Gets Hash Code
        /// </summary>
        public override int GetHashCode()
        {
            return 
                  base.GetHashCode() 
                ^ this.AspectRatio.GetHashCode() 
                ^ this.FarClipDistance.GetHashCode() 
                ^ this.FieldOfView.GetHashCode() 
                ^ this.NearClipdistance.GetHashCode();
        }
        /// <summary>
        /// Veiwport To String
        /// </summary>
        public override string ToString()
        {
            return String.Format
            (
                "Aspect: {0} FoV: {1} Near: {2} Far: {3}", 
                System.Math.Round(this.AspectRatio, 2), 
                this.FieldOfView, 
                this.NearClipdistance, 
                this.FarClipDistance
            );
        }
        #endregion
        //--------------------------------------------------------//
    }
    //------------------------------------------------------------//
}
